--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/marcmere/Box Sync/Shared_EffectofIncarceration_Pennslyvania/Replication Data/Connecticut SA Tables 03 and 04/CTCorrectionsData.log
  log type:  text
 opened on:  17 Dec 2016, 10:29:41

. 
. clear all 

. set more off

. 
. ***********************************************************************
. *
. * Table SA3: Registration and Turnout among Pop. First Incarcerated Post-2008 and Eligible in 2012
. *
. ***********************************************************************
. 
. use "CTcorrectionsvfreplication.dta", clear

. 
. label var reg_08 "Registered 2008 (1=yes)"

. label var vote_08final "Voted 2008  (1=yes)"

. label var reg_12 "Registered 2012 (1=yes)"

. label var vote_12final "Voted 2012 (1=yes)"

. label var delta_reg "Change in Registration 2012-2008"

. label var delta_vote "Change in Voting 2012-2008"

. 
. foreach var of varlist reg_12 vote_12final reg_08 vote_08final delta_reg delta_vote {
  2.  gen temp=`var'
  3.  local templabel : var label `var' 
  4.  if "`var'"=="reg_12" {
  5.   outsum temp using "SA_Table03_CTIncarcerationPanel.out", replace bracket ctitle("`templabel'")
  6.  }
  7.  else {
  8.   outsum temp using "SA_Table03_CTIncarcerationPanel.out", append bracket ctitle("`templabel'")
  9.  }
 10.  drop temp
 11.  
. }

. 
. ***********************************************************************
. *
. * Table SA4: Compares 2012 turnout of 2008 registrants who first went to prison to the general population 
. *
. ***********************************************************************
. 
. use "CTvfcorrectionsreplication.dta", clear

. 
. * Drops if missing covariates
. drop if missing(zip)
(3506 observations deleted)

. drop if missing(Age)
(0 observations deleted)

. 
. gen g_man=Gender=="male"

. gen g_unknown=Gender=="unknown"

. drop Gender

. 
. gen pid_d=PartyAffiliation=="DEM"

. gen pid_r=PartyAffiliation=="REP"

. drop PartyAffiliation

. 
. gen voted08=A2008G~=""

. drop A2008G

. 
. * Runs matched pair first (for labeling reasons)
. preserve

. keep if former_felon==0
(1626 observations deleted)

. save "temp_noprisonformerge.dta", replace
file temp_noprisonformerge.dta saved

. restore

. keep if former_felon==1
(2394082 observations deleted)

. rename Age Age_toprison

. rename ID ID_toprison 

. rename v_pres_general_12 v_pres_general_12_toprison

. count
 1626

. joinby g_man g_unknown pid_d pid_r zip voted08 using "temp_noprisonformerge.dta", unmatched(master)

. !erase "temp_noprisonformerge.dta"

/bin/bash: erase: command not found

. tab _merge

                       _merge |      Freq.     Percent        Cum.
------------------------------+-----------------------------------
          only in master data |          1        0.00        0.00
both in master and using data |  2,932,487      100.00      100.00
------------------------------+-----------------------------------
                        Total |  2,932,488      100.00

. drop if _merge~=3
(1 observation deleted)

. drop _merge

. 
. * Now score the age matches
. gen agediff=abs(Age-Age_toprison)

. * Require age to be withing 2.5 years on either side (5 year window)
. drop if agediff >2.5
(2657027 observations deleted)

. 
. gsort ID_toprison agediff ID

. drop if ID_toprison==ID_toprison[_n-1]
(273839 observations deleted)

. count
 1621

. 
. keep ID ID_toprison v_pres_general_12 v_pres_general_12_toprison voted08 Age Age_toprison

. 
. rename v_pres_general_12 X_GEN_2012_11_1

. rename v_pres_general_12_toprison X_GEN_2012_11_2

. rename Age age_1

. rename Age_toprison age_2

. gen unique_person_id_sent_1 = ID

. rename ID_toprison unique_person_id_sent_2 

. gen upis = _n

. 
. reshape long X_GEN_2012_11_ age_ unique_person_id_sent_, i(upis voted08) j(treat) 
(note: j = 1 2)

Data                               wide   ->   long
-----------------------------------------------------------------------------
Number of obs.                     1621   ->    3242
Number of variables                   9   ->       7
j variable (2 values)                     ->   treat
xij variables:
        X_GEN_2012_11_1 X_GEN_2012_11_2   ->   X_GEN_2012_11_
                            age_1 age_2   ->   age_
unique_person_id_sent_1 unique_person_id_sent_2->unique_person_id_sent_
-----------------------------------------------------------------------------

. replace treat=treat-1
(3242 real changes made)

. 
. rename X_GEN_2012_11_ X_GEN_2012_11

. rename treat former_felon

. rename age_ Age

. rename unique_person_id_sent_ unique_person_id_sent

. 
. areg X_GEN_2012_11 former_felon Age, absorb(upis) cluster(unique_person_id_sent)

Linear regression, absorbing indicators           Number of obs   =       3242
                                                  F(   2,   3134) =      86.82
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.5879
                                                  Adj R-squared   =     0.1751
                                                  Root MSE        =     0.3662

               (Std. Err. adjusted for 3135 clusters in unique_person_id_sent)
------------------------------------------------------------------------------
             |               Robust
X_GEN_201~11 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
former_felon |  -.1706986   .0130667   -13.06   0.000    -.1963188   -.1450784
         Age |  -.2341397   .1082355    -2.16   0.031    -.4463594     -.02192
       _cons |   8.172657   3.644355     2.24   0.025     1.027093    15.31822
-------------+----------------------------------------------------------------
        upis |   absorbed                                    (1621 categories)

. qui summ former_felon if e(sample)

. local numfelons=r(N)*r(mean)

. outreg2 using "SA_Table04_CTVoterFilePanel.out", replace se bracket label /*
> */ dec(3) symbol(***, **, *) addstat("Number treated to prison", `numfelons') /*
> */ addnote("Note: Cell entries are OLS estimates with robust standard errors in brackets. *p<.1; **p<.05; ***p<.01.") 
dir : seeout

. 
. * Runs regressions using full dataset
. use "CTvfcorrectionsreplication.dta", clear

. 
. * Drops if missing covariates
. drop if missing(zip)
(3506 observations deleted)

. drop if missing(Age)
(0 observations deleted)

. 
. label var v_pres_general_12 "Voted 2012 (1=yes)"

. 
. label var former_felon "Formerly Incarcerated (1=convicted after May 1, 2009 and released by September 30, 2012)"
note: label truncated to 80 characters

. 
. gen voted08=A2008G~=""

. drop A2008G

. label var voted08 "Voted 2008 (1=yes)"

. 
. label var Age "Age (years)"

. gen Age2=(Age^2)/100

. label var Age2 "Age squared / 100"

. 
. gen g_man=Gender=="male"

. gen g_unknown=Gender=="unknown"

. drop Gender

. 
. label var g_man "Gender=Male"

. label var g_unknown "Gender=Unknown"

. 
. gen pid_d=PartyAffiliation=="DEM"

. gen pid_r=PartyAffiliation=="REP"

. drop PartyAffiliation

. 
. label var pid_d "Registered Democrat (1=yes)"

. label var pid_r "Registered Republican (1=yes)"

. 
. count if former_felon==1
 1626

. local numfelons=r(N)

. 
. regress v_pres_general_12 former_felon, robust

Linear regression                                      Number of obs = 2395708
                                                       F(  1,2395706) = 2111.15
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.0004
                                                       Root MSE      =  .49975

------------------------------------------------------------------------------
             |               Robust
v_pres_ge~12 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
former_felon |  -.3688356   .0080274   -45.95   0.000    -.3845689   -.3531022
       _cons |   .4875318    .000323  1509.17   0.000     .4868986    .4881649
------------------------------------------------------------------------------

. outreg2 using "SA_Table04_CTVoterFilePanel.out", append se bracket label /*
> */ dec(3) symbol(***, **, *) addstat("Number treated to prison", `numfelons')
dir : seeout

. 
. areg v_pres_general_12 former_felon, robust absorb(zip) 

Linear regression, absorbing indicators           Number of obs   =    2395708
                                                  F(   1,2395375) =    1307.27
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.1020
                                                  Adj R-squared   =     0.1018
                                                  Root MSE        =     0.4737

------------------------------------------------------------------------------
             |               Robust
v_pres_ge~12 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
former_felon |  -.3082598   .0085258   -36.16   0.000      -.32497   -.2915496
       _cons |   .4874906   .0003062  1592.04   0.000     .4868905    .4880908
-------------+----------------------------------------------------------------
         zip |   absorbed                                     (332 categories)

. local numzipfe = e(df_a)+ 1

. outreg2 using "SA_Table04_CTVoterFilePanel.out", append se bracket label /*
> */ dec(3) symbol(***, **, *) addstat("Number treated to prison", `numfelons', "Zip code fixed effects", `numzipfe')
dir : seeout

. 
. areg v_pres_general_12 former_felon Age Age2 pid_d pid_r g_man g_unknown, robust absorb(zip) 

Linear regression, absorbing indicators           Number of obs   =    2395708
                                                  F(   7,2395369) =   29701.32
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.1651
                                                  Adj R-squared   =     0.1650
                                                  Root MSE        =     0.4567

------------------------------------------------------------------------------
             |               Robust
v_pres_ge~12 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
former_felon |  -.2495453   .0086721   -28.78   0.000    -.2665423   -.2325484
         Age |    .031382   .0000786   399.18   0.000     .0312279    .0315361
        Age2 |  -.0291366   .0000694  -420.12   0.000    -.0292725   -.0290007
       pid_d |   .0863368   .0006868   125.71   0.000     .0849907    .0876828
       pid_r |    .073851   .0008072    91.49   0.000     .0722689    .0754331
       g_man |  -.0223405   .0005963   -37.47   0.000    -.0235091   -.0211718
   g_unknown |  -.1638286   .0054711   -29.94   0.000    -.1745517   -.1531055
       _cons |  -.2867152   .0020579  -139.33   0.000    -.2907486   -.2826818
-------------+----------------------------------------------------------------
         zip |   absorbed                                     (332 categories)

. local numzipfe = e(df_a)+ 1

. outreg2 using "SA_Table04_CTVoterFilePanel.out", append se bracket label /*
> */ dec(3) symbol(***, **, *) addstat("Number treated to prison", `numfelons', "Zip code fixed effects", `numzipfe')
dir : seeout

. 
. areg v_pres_general_12 former_felon voted08 Age Age2 pid_d pid_r g_man g_unknown, robust absorb(zip) 

Linear regression, absorbing indicators           Number of obs   =    2395708
                                                  F(   8,2395368) =  166151.61
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.3859
                                                  Adj R-squared   =     0.3858
                                                  Root MSE        =     0.3917

------------------------------------------------------------------------------
             |               Robust
v_pres_ge~12 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
former_felon |  -.1446383   .0089107   -16.23   0.000    -.1621029   -.1271737
     voted08 |   .5253457   .0005592   939.51   0.000     .5242498    .5264417
         Age |   .0198277   .0000746   265.96   0.000     .0196815    .0199738
        Age2 |  -.0184166    .000066  -279.02   0.000     -.018546   -.0182873
       pid_d |   .0301494   .0005963    50.56   0.000     .0289805    .0313182
       pid_r |   .0359549   .0006906    52.07   0.000     .0346014    .0373084
       g_man |  -.0087502   .0005117   -17.10   0.000    -.0097531   -.0077474
   g_unknown |  -.0511794   .0044525   -11.49   0.000    -.0599061   -.0424528
       _cons |  -.3188791   .0018859  -169.08   0.000    -.3225755   -.3151827
-------------+----------------------------------------------------------------
         zip |   absorbed                                     (332 categories)

. local numzipfe = e(df_a)+ 1

. outreg2 using "SA_Table04_CTVoterFilePanel.out", append se bracket label /*
> */ dec(3) symbol(***, **, *) addstat("Number treated to prison", `numfelons', "Zip code fixed effects", `numzipfe')
dir : seeout

. 
. log close
      name:  <unnamed>
       log:  /Users/marcmere/Box Sync/Shared_EffectofIncarceration_Pennslyvania/Replication Data/Connecticut SA Tables 03 and 04/CTCorrectionsData.log
  log type:  text
 closed on:  17 Dec 2016, 10:31:08
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
